package com.dingli.servlet;

import com.dingli.dao.LoanDAO;
import com.dingli.dao.UserDAO;
import com.dingli.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/LoanServlet.do")
public class LoanServlet extends HttpServlet {
    private UserDAO userDAO = new UserDAO();
    private LoanDAO loanDAO = new LoanDAO();


    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取操作指令
        String action = req.getParameter("action");
        if (action.equals("index")) {
            req.getRequestDispatcher("./jsp/loan.jsp").forward(req, resp);

        } else if (action.equals("goLoan")) {
            req.getRequestDispatcher("./jsp/loan.jsp").forward(req, resp);


        } else if (action.equals("loan")) {
            String cid = req.getParameter("cid");
            User user = userDAO.selectById(Integer.parseInt(cid));
            if (user == null) {
                resp.getWriter().println("卡号有误，无查询结果!");
            }
        }
    }
}